/**
 * Licensee: DuKe TeAm
 * License Type: Purchased
 */
package ormsamples;

import org.orm.*;
public class RetrieveAndUpdateCineData {
	public void retrieveAndUpdateTestData() throws PersistentException {
		PersistentTransaction t = orm.CinePersistentManager.instance().getSession().beginTransaction();
		try {
			orm.DAOFactory lDAOFactory = orm.DAOFactory.getDAOFactory();
			orm.dao.PeliculaDAO lormPeliculaDAO = lDAOFactory.getPeliculaDAO();
			orm.Pelicula lormPelicula = lormPeliculaDAO.loadPeliculaByQuery(null, null);
			// Update the properties of the persistent object
			lormPeliculaDAO.save(lormPelicula);
			orm.dao.GeneroDAO lormGeneroDAO = lDAOFactory.getGeneroDAO();
			orm.Genero lormGenero = lormGeneroDAO.loadGeneroByQuery(null, null);
			// Update the properties of the persistent object
			lormGeneroDAO.save(lormGenero);
			orm.dao.ClasificacionDAO lormClasificacionDAO = lDAOFactory.getClasificacionDAO();
			orm.Clasificacion lormClasificacion = lormClasificacionDAO.loadClasificacionByQuery(null, null);
			// Update the properties of the persistent object
			lormClasificacionDAO.save(lormClasificacion);
			orm.dao.SalaDAO lormSalaDAO = lDAOFactory.getSalaDAO();
			orm.Sala lormSala = lormSalaDAO.loadSalaByQuery(null, null);
			// Update the properties of the persistent object
			lormSalaDAO.save(lormSala);
			t.commit();
		}
		catch (Exception e) {
			t.rollback();
		}
		
	}
	
	public void retrieveByCriteria() throws PersistentException {
		System.out.println("Retrieving Pelicula by PeliculaCriteria");
		orm.PeliculaCriteria peliculaCriteria = new orm.PeliculaCriteria();
		// Please uncomment the follow line and fill in parameter(s)
		//peliculaCriteria.id.eq();
		System.out.println(peliculaCriteria.uniquePelicula());
		
		System.out.println("Retrieving Genero by GeneroCriteria");
		orm.GeneroCriteria generoCriteria = new orm.GeneroCriteria();
		// Please uncomment the follow line and fill in parameter(s)
		//generoCriteria.id.eq();
		System.out.println(generoCriteria.uniqueGenero());
		
		System.out.println("Retrieving Clasificacion by ClasificacionCriteria");
		orm.ClasificacionCriteria clasificacionCriteria = new orm.ClasificacionCriteria();
		// Please uncomment the follow line and fill in parameter(s)
		//clasificacionCriteria.id.eq();
		System.out.println(clasificacionCriteria.uniqueClasificacion());
		
		System.out.println("Retrieving Sala by SalaCriteria");
		orm.SalaCriteria salaCriteria = new orm.SalaCriteria();
		// Please uncomment the follow line and fill in parameter(s)
		//salaCriteria.id.eq();
		System.out.println(salaCriteria.uniqueSala());
		
	}
	
	
	public static void main(String[] args) {
		try {
			RetrieveAndUpdateCineData retrieveAndUpdateCineData = new RetrieveAndUpdateCineData();
			try {
				retrieveAndUpdateCineData.retrieveAndUpdateTestData();
				//retrieveAndUpdateCineData.retrieveByCriteria();
			}
			finally {
				orm.CinePersistentManager.instance().disposePersistentManager();
			}
		}
		catch (Exception e) {
			e.printStackTrace();
		}
	}
}
